<?php

$plugin_info = array(
  'pi_name' => 'Youtubee',
  'pi_version' => '1.0',
  'pi_author' => 'Iain Urquhart',
  'pi_author_url' => 'http://iain.co.nz/',
  'pi_description' => 'Youtubee',
  'pi_usage' => Youtubee::usage()
  );

class Youtubee
{
	var $return_data = '';
	
	function Youtubee( $str = '' )
	{
		global $TMPL;
		
		$the_content = '';
		$width = $TMPL->fetch_param('width');
		
		$height = 340; 
		$height = $TMPL->fetch_param('height'); 

		if ($str == '')
		{
        	$the_content = $TMPL->tagdata;
        	preg_match('/[\\?\\&]v=([^\\?\\&]+)/',$the_content,$matches);
		}
		if ($width == '')
		{
			$width = 480;
		}
		if ($height == '')
		{
			$height = 340;
		}
		
		$this->return_data = '';
		foreach ($matches as &$match) {
	   		$r = '';
	   		$r .= "<object width=\"";
			$r .= $width;
			$r .= "\" height=\"";
			$r .= $height;
			$r .= "\"><param name=\"movie\" value=\"";
			$r .= $match;
			$r .= "\"></param><param name=\"wmode\" value=\"transparent\" ></param><embed src=\"http://www.youtube.com/v/";
			$r .= $match;
			$r .= "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"";
			$r .= $width;
			$r .= "\" height=\"";
			$r .= $height;
			$r .= "\"></embed></object>";
	   		
	   		$this->return_data = $r;
   		
   		}

	}

  // ----------------------------------------
  //  Plugin Usage
  // ----------------------------------------

  function usage()
  {
  ob_start(); 
  ?>
  
	{exp:youtubee width="480" height="340"}http://www.youtube.com/watch?v=xxxxx{/exp:youtubee}
	
	Will output the youtube player from just the url...

  <?php
  $buffer = ob_get_contents();
	
  ob_end_clean(); 

  return $buffer;
  }
  // END

}
?>